package com.ouyy.volunteerservice.volunteer.controller;

import com.ouyy.volunteerservice.volunteer.domain.po.Volunteers;
import com.ouyy.volunteerservice.volunteer.service.OrganizationsService;
import com.ouyy.volunteerservice.volunteer.service.VolunteersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class RegisterController {

    @Autowired
    private VolunteersService volunteersService;
    @Autowired
    private OrganizationsService organizationsService;

    @PostMapping(value = "/register")
    public ResponseEntity<?> register(@RequestBody Volunteers volunteers){
        if(volunteersService.findByUsername(volunteers.getName())){
            return ResponseEntity.status(401).body("用户已存在！");
        }else {
            boolean isInsert = volunteersService.insert(volunteers);
            if (isInsert){
                return ResponseEntity.ok(volunteers);
            }
        }
        return ResponseEntity.ok(volunteers);
    }
}
